package com.lc.tgxm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lc.tgxm.R;
import com.lc.tgxm.model.Msg;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * MyNormalAdapter
 * Created by Administrator on 2016/12/16.
 */
public class MyNormalAdapter extends BaseAdapter {
    private Context context;
    private List<Msg> list;

    public MyNormalAdapter(Context context, List<Msg> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_mlv, parent);
            ScaleScreenHelperFactory.getInstance().loadViewGroup((ViewGroup) convertView);
            holder = new ViewHolder();
            holder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tvMsg = (TextView) convertView.findViewById(R.id.tv_line_1);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Msg msg = (Msg) getItem(position);
        holder.tvTitle.setText(msg.title);
        holder.tvMsg.setText(msg.msg);

        return convertView;
    }

    private class ViewHolder {
        private TextView tvTitle;
        private TextView tvMsg;
    }

}
